<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <c:set var="projectName" value='${fnc:getDBConfig("sys","common","project.name")}' />
    <c:set var="projectCopyright" value='${fnc:getDBConfig("sys","common","project.copyright")}' />
    <c:set var="projectVersion" value='${fnc:getDBConfig("sys","common","project.version")}' />
    <title>${projectName.configValue} - 后台管理</title>
    <%@ include file="include/head.jsp"%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/3rd-lib/common/css/font-awesome.min.css">
    <link href="${ctxStatic}/3rd-lib/common/css/jquery.scrollbar.min.css" rel="stylesheet">
    <link href="${ctxStatic}/3rd-lib/common/css/nth.tabs.min.css" rel="stylesheet">
    <style>
        body{overflow-y:hidden;}
        .am-topbar{margin-bottom:0;}
        .am-footer{border-top: 1px solid #ddd;z-index: 20000;padding: 0;}
        .am-topbar-inverse{color:#fff;}
        .am-topbar-nav > li.am-active > a:after{border:none;}
        .am-topbar-nav > li > a:hover:after{border:none;}
        .am-dropdown-content{margin:0;}
        .am-dropdown-content:after, .am-dropdown-content:before{border: none;}
        .am-with-topbar-fixed-bottom{padding-bottom:0px;}
    </style>
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，平台暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
    以获得更好的体验！</p>
<![endif]-->
<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-topbar-brand">
        <a href="${ctx}"><strong>${projectName.configValue}</strong> <small><sup>${projectVersion.configValue}</sup></small></a>
    </div>
    <div class="am-collapse am-topbar-collapse">
        <ul id="menu-top" class="am-nav am-nav-pills am-topbar-nav"><!-- 菜单显示 --></ul>
        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
            <li class="am-dropdown">
                <a class="am-dropdown-toggle" href="javascript:;">
                    欢迎您，${empty loginUser.name?loginUser.username:loginUser.name}
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="#userInfo" data-id="userInfo" data-title="用户信息" onclick="link(this,'${ctx}/user/userInfo')"><span class="am-icon-user"></span> 用户信息</a></li>
                    <li><a href="#changePassword" data-id="changePassword" data-title="修改密码" onclick="link(this,'${ctx}/user/changePassword')"><span class="am-icon-key"></span> 修改密码</a></li>
                    <li><a href="#setting" data-id="setting" data-title="系统设置" onclick="link(this,'${ctx}/toPage?path=setting')"><span class="am-icon-cog"></span> 系统设置</a></li>
                </ul>
            </li>
            <shiro:hasPermission name="msgReceive:view"><li><a href="#msgBox" data-id="msgBox" data-title="收件箱" onclick="link(this,'${ctx}/msgReceive?msgSend.type=mail&status=-1')"><span class="am-icon-envelope-o"></span> 收件箱 <span class="am-badge am-badge-warning" id="emailNotice" style="display: none;">0</span></a></li></shiro:hasPermission>
            <li><a href="${ctx}/logout" onclick="return iuConfirm('确认要退出吗？', this.href)"><span class="am-icon-sign-out"></span> 退出</a></li>
        </ul>
    </div>
</header>
<!-- 面包屑导航 -->
<div id="crumb" style="display: none;">
    <ol class="am-breadcrumb" style="margin-top: 50px;">
        <li><a href="${ctx}" target="_top" class="am-icon-home">首页</a></li>
        <li class="am-active">欢迎页</li>
    </ol>
    <div class="content-wrapper">
        <iframe id="main-content" src="${ctx}/welcome" style="width:100%;" scrolling="no" frameborder="no"></iframe>
    </div>
</div>
<!-- 标签页导航 -->
<div class="nth-tabs" id="tabs" style="margin-top: 50px;display: none;"></div>

<footer data-am-widget="footer"
        class="am-footer am-footer-default am-topbar-fixed-bottom">
    <div class="am-footer-miscs">
        <p>${projectCopyright.configValue} ${projectVersion.configValue}</p>
    </div>
</footer>
<%@ include file="include/bottom.jsp"%>
<script type="text/javascript" src="${ctxStatic}/3rd-lib/common/js/jquery.scrollbar.min.js"></script>
<script type="text/javascript" src="${ctxStatic}/3rd-lib/common/js/nth.tabs.min.js"></script>
<script>
    var nthTabs;//tab组件
    var iuHeight = 0;//设置IFrame的高度
    $(document).ready(function(){
        iuHeight = $(window).height()-122;
        //菜单数据
        var menus = [<c:forEach items="${menus}" var="menu" varStatus="status">{id:"${menu.id}",name:"${menu.name}",url:"${menu.url}",icon:"${menu.icon}",pId:"${menu.parentId}",isSub:${menu.isSub}}<c:if test="${!status.last}">,</c:if></c:forEach>];
        //获取系统设置
        var menu = getCookie("sys.menu");//导航显示
        if(menu=="left"){
            //左侧显示

        }else if(menu=="right"){
            //右侧显示

        }else{
            //默认顶部显示
            var $menuTop = $("#menu-top");
            for(var i=0;i<menus.length;i++){
                //循环第一层菜单
                if(menus[i].pId=="0"){
                    if(menus[i].isSub){
                        var subMenu = '<li class="am-dropdown"><a class="am-dropdown-toggle" href="javascript:;">';
                        if(menus[i].icon!=''){
                            subMenu += '<span class="'+menus[i].icon+'"></span> '+menus[i].name+'</a>';
                        }else{
                            subMenu += menus[i].name+'</a>';
                        }
                        subMenu += '<ul class="am-dropdown-content">';
                        //循环第二层
                        for(var j=0;j<menus.length;j++){
                            if(menus[i].id==menus[j].pId){
                                if(menus[j].url.indexOf("http://")==0 || menus[j].url.indexOf("https://")==0){
                                    if(menus[j].icon!=''){
                                        subMenu += '<li><a href="'+menus[j].url+'" target="_blank"><span class="'+menus[j].icon+'"></span> '+menus[j].name+'</a></li>';
                                    }else{
                                        subMenu += '<li><a href="'+menus[j].url+'" target="_blank">'+menus[j].name+'</a></li>';
                                    }
                                }else{
                                    if(menus[j].icon!=''){
                                        subMenu += '<li><a href="#'+menus[j].id+'" data-id="'+menus[j].id+'" data-title="'+menus[j].name+'" onclick="link(this,\'${ctx}/'+menus[j].url+'\')"><span class="'+menus[j].icon+'"></span> '+menus[j].name+'</a></li>';
                                    }else{
                                        subMenu += '<li><a href="#'+menus[j].id+'" data-id="'+menus[j].id+'" data-title="'+menus[j].name+'" onclick="link(this,\'${ctx}/'+menus[j].url+'\')"> '+menus[j].name+'</a></li>';
                                    }
                                }
                            }
                        }
                        subMenu += '</ul></li>';
                        $menuTop.append(subMenu);
                    }else{
                        if(menus[i].url.indexOf("http://")==0 || menus[i].url.indexOf("https://")==0){
                            if(menus[i].icon!=''){
                                $menuTop.append('<li><a href="'+menus[i].url+'" target="_blank"><span class="'+menus[i].icon+'"></span> '+menus[i].name+'</a></li>');
                            }else{
                                $menuTop.append('<li><a href="'+menus[i].url+'" target="_blank"> '+menus[i].name+'</a></li>');
                            }
                        }else{
                            if(menus[i].icon!=''){
                                $menuTop.append('<li><a href="#'+menus[i].id+'" data-id="'+menus[i].id+'" data-title="'+menus[i].name+'" onclick="link(this,\'${ctx}/'+menus[i].url+'\')"><span class="'+menus[i].icon+'"></span> '+menus[i].name+'</a></li>');
                            }else{
                                $menuTop.append('<li><a href="#'+menus[i].id+'" data-id="'+menus[i].id+'" data-title="'+menus[i].name+'" onclick="link(this,\'${ctx}/'+menus[i].url+'\')"> '+menus[i].name+'</a></li>');
                            }
                        }
                    }
                }
            }
        }
        var email = getCookie("sys.email");//是否接受邮件
        if(email=="1"){
            get("${ctx}/msgReceive/notice?msgSend.type=mail",function(data){
                if(data>0){
                    $("#emailNotice").html(data);
                    $("#emailNotice").show();
                }else{
                    $("#emailNotice").hide();
                }
            });
        }
        //面包屑导航
        var crumbs = getCookie("sys.crumbs");
        if(crumbs=="tabs"){
            $("#tabs").show();
            nthTabs = $("#tabs").nthTabs();
            nthTabs.addTab({
                id:'welcome',
                title:'欢迎页',
                content:'<iframe src="${ctx}/welcome" style="width:100%;height:'+iuHeight+'px" scrolling="no" frameborder="no"></iframe>',
                active:true,
                allowClose:false
            });
            nthTabs.setActTab('welcome');//切换标签
            nthTabs.locationTab();//定位到当前标签
            $("#tabs").on('click','a[data-toggle="tabs"]',function(){
                var $this = $(this);
                if(!$this.parent().hasClass('active')){
                    $this.parent().siblings().removeClass('active');
                    $this.parent().addClass('active');
                    $(".tab-pane").removeClass('active');
                    $($this.attr('href')).addClass('active');
                }
            });
        }else{
            //默认面包屑导航
            $("#crumb").show();
            //计算高度
            $("#main-content").height(iuHeight);
        }
        //导航自定事件
        $(".am-dropdown").on("mouseover",function(){
            $(this).find(".am-dropdown-content").show();
        });
        $(".am-dropdown").on("mouseout",function(){
            $(this).find(".am-dropdown-content").hide();
        });

        //初始化
        var hash = location.hash;
        if(hash){
            var $ele = $("a[href='"+hash+"']");
            $ele && $ele.trigger('click');
        }
    });

    //跳转
    function link(ele,url){
        //判断导航类型
        var $ele = $(ele);
        var crumbs = getCookie("sys.crumbs");
        if(crumbs=="tabs"){
            //新增之前，判断是否存在
            if($("#"+$ele.attr("data-id")).length<=0){
                nthTabs.addTab({
                    id:$ele.attr("data-id"),
                    title:$ele.attr("data-title"),
                    content:'<iframe src="'+url+'" style="width:100%;height:'+iuHeight+'px" scrolling="no" frameborder="no"></iframe>',
                });
            }
            nthTabs.setActTab($ele.attr("data-id"));//切换标签
            nthTabs.locationTab();//定位到当前标签
        }else{
            $("#crumb").find(".am-active").eq(0).html($ele.attr("data-title"));
            $("#main-content").attr("src",url);
        }
    }
</script>
</body>
</html>